﻿#pragma once

_NAMESPACE_BEGIN

/// 常用的编码格式转换类
class CodeConvert
{
public:
	
	/// 单体类声明
	SINGLETON_HELPER(CodeConvert)

	/// 多字符集转Unicode(std::wstring出)
	void MultiByte2Unicode(const char* in,tstring& out,int inlen=-1);

	/// 多字符集转Unicode(TCHAR*出)
	void MultiByte2Unicode(const char* in,TCHAR out[],int outsize,int inlen=-1);

	/// Unicode转多字符集
	void Unicode2MultiByte(const TCHAR* in,std::string& out,int inlen=-1);

	/// Unicode转多字符集
	void Unicode2MultiByte(const TCHAR* in,char out[],int outsize,int inlen=-1);

	/// Unicode转UTF8
	void Unicode2UTF8(const TCHAR* in,std::string& out,int inlen=-1);

	/// Unicode转UTF8
	void Unicode2UTF8(const TCHAR* in,char out[],int outsize,int inlen=-1);

	/// UTF8转Unicode
	void UTF8_2Unicode(const char* in,tstring& out,int inlen=-1);

	/// UTF8转Unicode
	void UTF8_2Unicode(const char* in,TCHAR out[],int outsize,int inlen=-1);

	bool ExistChinese(CONST_REF(tstring) tstr);

	/// 任意类型转成Unicode
	void Any2Unicode(CONST_REF(boost::any) a,tstring& out);

protected:
	void WChar2Char(UINT codepage,const TCHAR* in,std::string& out,int inlen=-1);
	void WChar2Char(UINT codepage,const TCHAR* in,char out[],int outsize,int inlen=-1);
	void Char2WChar(UINT codepage,const char* in,tstring& out,int inlen=-1);
	void Char2WChar(UINT codepage,const char* in,TCHAR out[],int outsize,int inlen=-1);

private:
};

_NAMESPACE_END